package com.jifeng.br.pjj.bookreader.controller.admin;


import com.jifeng.br.pjj.bookreader.entity.CategoryEntity;
import com.jifeng.br.pjj.bookreader.service.CategoryService;
import com.jifeng.br.pjj.bookreader.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 分类表 前端控制器
 * </p>
 *
 * @author 机蜂
 * @since 2023-07-11
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    public R page(int page, int limit, CategoryEntity category) {
        return R.data(categoryService.getPage(page, limit, category));
    }

    @GetMapping("/info/{categoryId}")
    public R info(@PathVariable int categoryId) {
        return R.data(categoryService.getById(categoryId));
    }

    @PostMapping("/update")
    public R update(@RequestBody CategoryEntity category) {
        categoryService.saveOrUpdate(category);
        return R.ok();
    }

    @DeleteMapping("/delete/{categoryId}")
    public R delete(@PathVariable int categoryId) {
        categoryService.removeById(categoryId);
        return R.ok();
    }

    @GetMapping("/select")
    public R select() {
        return R.data(categoryService.list());
    }
}

